Skip to content

Refactor permission check redirect#2109

Merged
alexandrudanpop merged 9 commits intomainfrom
feat/rbac-refactor
Mar 17, 2026
Merged

Refactor permission check redirect#2109
alexandrudanpop merged 9 commits intomainfrom
feat/rbac-refactor

Conversation

@alexandrudanpop
Copy link
Copy Markdown
Contributor

@alexandrudanpop alexandrudanpop commented Mar 11, 2026

Fixes OPS-3916

Copilot AI review requested due to automatic review settings March 11, 2026 10:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors permission handling in several React UI routes by introducing a shared hook that checks access and redirects when a required permission is missing.

Changes:

  • Added useCheckAccessAndRedirect(permission) hook to centralize permission-check + redirect logic.
  • Applied the new hook to OpenOps Tables, OpenOps Analytics, and Flows routes to prevent rendering when access is missing.
  • Updated side-menu link metadata to lock Tables/Analytics links based on write permissions.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/react-ui/src/app/common/hooks/authorization-hooks.ts Adds useCheckAccessAndRedirect hook for permission-based redirects.
packages/react-ui/src/app/routes/openops-tables/index.tsx Uses the new access+redirect hook for Tables route.
packages/react-ui/src/app/routes/openops-analytics/index.tsx Uses the new access+redirect hook for Analytics route.
packages/react-ui/src/app/routes/flows/index.tsx Adds access+redirect gate to Flows list route.
packages/react-ui/src/app/routes/flows/id/index.tsx Adds access+redirect gate to Flow builder route.
packages/react-ui/src/app/features/templates/components/select-flow-template-dialog-content.tsx Replaces local permission check with redirecting hook in a dialog context.
packages/react-ui/src/app/features/navigation/lib/menu-links-hook.ts Locks Tables/Analytics menu links based on permissions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread packages/react-ui/src/app/common/hooks/authorization-hooks.ts
Comment on lines +100 to +102
const hasWriteFlowPermission = useCheckAccessAndRedirect(
Permission.WRITE_FLOW,
);
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dialog content previously used checkAccess only to disable the “use template” action; switching to useCheckAccessAndRedirect will navigate the user away from the current page when they lack WRITE_FLOW, even though the UI already supports a read-only experience (it just omits useTemplate). Consider using useAuthorization().checkAccess here (no redirect), or make the redirect hook optional/configurable so non-route components don’t cause unexpected navigation.

Copilot uses AI. Check for mistakes.
@@ -51,6 +53,10 @@ const FlowBuilderPage = () => {
refetchOnWindowFocus: 'always',
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useQuery will still fetch the flow even when hasAccess is false (the redirect happens in an effect after render). To avoid unnecessary API calls (and caching potentially sensitive data client-side), gate the query with an enabled condition that includes hasAccess (and flowId).

Suggested change
refetchOnWindowFocus: 'always',
refetchOnWindowFocus: 'always',
enabled: Boolean(hasAccess && flowId),

Copilot uses AI. Check for mistakes.
Comment thread packages/react-ui/src/app/common/hooks/authorization-hooks.ts
@linear
Copy link
Copy Markdown

linear bot commented Mar 17, 2026

@sonarqubecloud
Copy link
Copy Markdown

Comment on lines +56 to +58
if (!hasAccess) {
return null;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need it? In theory it is not reachable as user will be redirected. But we can keep it to be more confident

@alexandrudanpop alexandrudanpop merged commit 8086591 into main Mar 17, 2026
21 checks passed
@alexandrudanpop alexandrudanpop deleted the feat/rbac-refactor branch March 17, 2026 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants